#ifndef SCREEN_RAY_PICKER_H
#define SCREEN_RAY_PICKER_H

#include "matrix.h"
#include "viewInfo.h"
#include "math.h"

class ScreenRayPicker
{
	double m_lfAspect, m_lfAngle, m_lfTanAngle, m_lfNearClip, m_lfInvAspect;
	const viewInfo * m_pView;

	mdsVector<3, double> m_lastVecPicked, m_rayPos;
	bool m_lastVecValid;
public:
	ScreenRayPicker(void);
	~ScreenRayPicker(void);
	inline void SetAspect(double lfAspect) { m_lfAspect = lfAspect; m_lfInvAspect = 1.0/lfAspect; }
	inline void SetAngle(double lfAngle) { m_lfAngle = lfAngle; m_lfTanAngle = tan(0.5*lfAngle);}
	inline void SetNearClip(double lfNearClip) { m_lfNearClip = lfNearClip; }
	inline void SetView(const viewInfo & view)
	{
		m_pView = &view;
	}

	inline bool IsLastVecValid() const { return m_lastVecValid; }

	inline mdsVector<3, double> GetRayDir() const { return m_lastVecPicked; }
	inline mdsVector<3, double> GetRayPos() const { return m_rayPos; }

	bool PickRayFromScreenCoord(const mdsVector<2, double> & p2ScreenCoord);
	bool PickRayFromScreenCoordStateless(const mdsVector<2, double> & p2ScreenCoord, mdsRay<double> & rayOut) const;

};

#endif